<?php
include "./base.php";

//1.获取用户名和密码
$username = $_POST['username'];
$password = $_POST['password'];

//2.链接数据库，将数据插入数据库中
$link = mysqli_connect("127.0.0.1", 'root', 'root', 'xiaomi-shop');

//3.查询数据库中是否有用户名和密码
$sql = "SELECT * FROM `userinfo` WHERE `username`='$username' AND `password`='$password'";
$result = mysqli_query($link, $sql);

//4.解析结果
$arr = mysqli_fetch_assoc($result);
if ($arr) {
    $arr = array('code' => 1); //登录成功，有数据
} else {
    $arr = array('code' => 0); //登录失败
}
$jsonstr = json_encode($arr);
echo $jsonstr;

//5.断开连接
mysqli_close($link);
